package com.chenxi.mapper;

import com.chenxi.bean.Order;
import com.chenxi.bean.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface OrderMapper {
    // 查询订单信息（订单信息包含所属用户）
    @Results(value = {
            @Result(property = "id", column = "id"),
            @Result(property = "orderTime", column = "orderTime"),
            @Result(property = "total", column = "total"),
            // 根据userId的值,调用one注解的查询语句查询到User对象。赋值给user属性，返回类型（javaType = User.class）
            @Result(property = "user", column = "userId", javaType = User.class,
                    one = @One(select = "com.chenxi.mapper.UserMapper.findById"))
    })
    @Select(value = "select * from orders")
    List<Order> findOrderAndUser();

    @Select(value = "select * from orders where userId = #{userId}")
    public List<Order> findOrderListByUserId(int userId);
}
